﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Omniture.Common;

namespace Omniture.Studio.Objects
{
	public class Licensing
	{
		public static bool ApplyLicense(string key)
		{
			FileInfo fi = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
			string folder = fi.DirectoryName;
			string fileName = Path.Combine(folder, "omniture.studio.key");

			if (!File.Exists(fileName))
			{
				StreamWriter sw = File.CreateText(fileName);
				sw.Write(key);
				sw.Close();
			}

			return true;
		}

		public static bool CheckLicense()
		{
			//return (DateTime.Now < new DateTime(2009, 12, 31));
			return true;

			//FileInfo fi = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
			//string folder = fi.DirectoryName;
			//string fileName = Path.Combine(folder, "omniture.studio.key");

			//bool retval = true;
			//if (!File.Exists(fileName))
			//{
			//  retval = false;
			//}
			//else
			//{
			//  StreamReader sr = File.OpenText(fileName);
			//  string text = sr.ReadToEnd();
			//  sr.Close();

			//  text = SecurityHelper.DecryptKey(text);
			//  DateTime dt;
			//  if (!DateTime.TryParse(text, out dt))
			//  {
			//    retval = false;
			//  }
			//  else
			//  {
			//    if (dt < DateTime.Now)
			//      retval = false;
			//  }

			//}

			//if (!retval)
			//{
			//  //show message about licensing
			//  MessageBox.Show("This product has not been licensed. Please go to the Help menu and select Licensing.", "Licensing", MessageBoxButtons.OK, MessageBoxIcon.Information);
			//}

			//return retval;

		}

	}
}
